import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router';
import NestedLayout from '../layouts/NestedLayout.vue';
import BlankLayout from '../layouts/BlankLayout.vue';
import LoginPage from '../views/LoginPage.vue';

const hasGithubPages = import.meta.env.VITE_GHPAGES;

export default createRouter({
  history: hasGithubPages ? createWebHashHistory() : createWebHistory(),
  routes: [
    {
      path: '/',
      name: 'index',
      meta: { title: '系统' },
      component: NestedLayout,
      redirect: '/home',
      children: [
        {
          path: '/home',
          name: 'home',
          meta: { title: '首页', icon: 'icon-icon-test', flat: true },
          component: () => import('../views/WelcomePage.vue'),
        },
        {
          path: '/userCenter',
          name: 'userCenter',
          meta: { title: '个人中心', icon: 'icon-tuijian', flat: true },
          component: () => import('../views/user/userCenter.vue'),
        },

        {
          path: '/userManage',
          name: 'userManage',
          meta: { title: '用户管理', icon: 'icon-tuijian', flat: true },
          component: () => import('../views/user/userManage.vue'),
        },
        {
          path: '/tenant',
          name: 'tenant',
          meta: { title: '租户管理', icon: 'icon-tuijian', flat: true },
          component: () => import('../views/tenant/tenant.vue'),
        },
      ],
    },
    {
      path: '/login',
      name: 'login',
      meta: { title: '登录', icon: 'icon-icon-test' },
      component: LoginPage,
    },
    {
      path: '/:pathMatch(.*)*',
      component: () => import('../views/exception/404.vue'),
    },
  ],
});
